<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    // 基于函数 声明函数的时候加上*
    function *fn(){
        yield "王五";
        yield "李四";
        yield "张三";
    }
    let interatorObj = fn();    //获取一个可迭代的对象
    // console.log(interatorObj);
    // console.log(interatorObj.next());
    // console.log(interatorObj.next());
    // console.log(interatorObj.next());
    // console.log(interatorObj.next());
    
    
    // for(let val of interatorObj){
    //     console.log(val);
    // }


    // 生成器处理异步
    function run(){
        let res = interatorObj.next();
        console.log(res);
        if(res.done){
            console.log('迭代完成了')
        }else{
            // setTimeout(()=>{
            //     run();
            // },1000);
            setTimeout(run,1000);
        }
    }
    run();

</script>